package srcBlackJack;

import lib.ArgumentValidator;

public class TransitionInfo 
{
    Action applicableAction;
    BlackJackState destinationState;
    double probability;
    int reward;
    
    public TransitionInfo(
            Action applicableAction,
            BlackJackState destinationState,
            double probability,
            int reward) 
    {
        ArgumentValidator.IsBetweenBothInclusive("probability", probability, 0.0, 1.0);
        
        this.applicableAction = applicableAction;
        this.destinationState = destinationState;
        this.probability = probability;
        this.reward = reward;
    }

    public Action ApplicableAction() {
        return applicableAction;
    }

    public BlackJackState DestinationState() {
        return destinationState;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        TransitionInfo other = (TransitionInfo) obj;
        if (applicableAction != other.applicableAction)
            return false;
        if (destinationState == null) {
            if (other.destinationState != null)
                return false;
        } else if (!destinationState.equals(other.destinationState))
            return false;
        return true;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime
                * result
                + ((applicableAction == null) ? 0 : applicableAction.hashCode());
        result = prime
                * result
                + ((destinationState == null) ? 0 : destinationState.hashCode());
        return result;
    }

    public double Probability() {
        return probability;
    }

    public int Reward() {
        return reward;
    }

    public void SetProbability(double probability) 
    {
        this.probability = probability;
    }

    @Override
    public String toString() {
        return String
                .format("TransitionInfo [applicableAction=%s, destinationState=%s, probability=%s, reward=%s]",
                        applicableAction, destinationState, probability, reward);
    }
}
